<template>
  <!--模态窗 多行-->
  <transition
    name="custom-classes-transition"
    enter-active-class="animated fadeInDown"
    leave-active-class="animated fadeOutUp"
  >
    <div class="modal-ctrl-body" v-show="addModalObj.isShow">
      <div class="modal-ctrl-main map-ctrl">

        <div class="modal-title">
          <p>新增摄像头信息</p>
        </div>

        <div class="modal-ctrl-content clear-false">

          <div class="map-body f-l">
            <pointMap
              v-if="addModalObj.isShow"
              ref="pointMapRef"
              :point="point"
              :actionType="actionType"
              :isPolygonButton="isPolygonButton"
              @pointCoordinate="pointCoordinate"
            ></pointMap>
          </div>
          <div class="map-body f-l" :style="{right: openMapDataContentIsShow ? '0':'-640px'}">

            <div class="modal-row f-l" >
              <div class="modal-form-key f-l indispensable">
                账号：
              </div>
              <input type="text" maxlength="32" v-model="AddModalData.accout" class="modal-text f-l">
            </div>

            <div class="modal-row f-l" >
              <div class="modal-form-key f-l indispensable">
                密码：
              </div>
              <input type="text" maxlength="16" v-model="AddModalData.password" class="modal-text f-l">
            </div>

            <div class="modal-row f-l" >
              <div class="modal-form-key f-l indispensable">
                地址：
              </div>
              <input type="text" maxlength="128" v-model="AddModalData.address" class="modal-text f-l">
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l indispensable">
                名称：
              </div>
              <input type="text" maxlength="32" v-model="AddModalData.name" class="modal-text f-l">
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l indispensable">
                设备号：
              </div>
              <input type="text" maxlength="16" v-model="AddModalData.num" class="modal-text f-l">
            </div>

            <div class="modal-row f-l" >
              <div class="modal-form-key f-l indispensable">
                所属单位：
              </div>
              <input type="text" v-model="stationName" @click="getStationTree" readonly="readonly" class="modal-text f-l" >
              <input type="hidden" v-model="AddModalData.stationid">
              <div class="sectionTree" v-show="sectionTreeIShow">
                <div id="sectionTree" class="ztree sectionTree-box"></div>
              </div>
            </div>

            <div class="modal-row f-l" >
              <div class="modal-form-key f-l indispensable">
                IP地址：
              </div>
              <input type="text" v-model="AddModalData.ipAddress" class="modal-text f-l">
            </div>

            <div class="modal-row f-l" >
              <div class="modal-form-key f-l indispensable">
                安装时间：
              </div>
              <div class="input-group date" id="date1">
                <span class="input-group-addon glyphicon glyphicon-list"><i class="fa fa-calendar"></i></span>
                <input type="hidden" ref="installTime">
                <input type="text" ref="installTime" readonly="readonly" id="addDatetimepicker" class="form-control" required="required" data-date-format="dd-mm-yyyy">
              </div>
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l">
                摄像头类型：
              </div>
              <select class="modal-text" @change="selectCameraType" :value="AddModalData.category">
                <option value="1">枪机</option>
                <option value="2">球机</option>
              </select>
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l">
                是否在线：
              </div>
              <select class="modal-text" @change="selectIsOnline" :value="AddModalData.isonline">
                <option value="1">在线</option>
                <option value="2">离线</option>
              </select>
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l">
                维护单位：
              </div>
              <input type="text" maxlength="100" placeholder="最长100个字符" v-model="AddModalData.maintenanceUnit" class="modal-text f-l">
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l">
                维护单位电话：
              </div>
              <input type="text" v-model="AddModalData.maintenanceUnitTel" class="modal-text f-l">
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l">
                纬度：
              </div>
              <input type="text" v-model="AddModalData.latitude" maxlength="11" class="modal-text f-l">
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l">
                经度：
              </div>
              <input type="text" v-model="AddModalData.longitude" maxlength="12" class="modal-text f-l">
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l">
                杆号：
              </div>
              <input type="text" maxlength="15" placeholder="最长15个字符" v-model="AddModalData.poleNum" class="modal-text f-l">
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l">
                点位名称：
              </div>
              <input type="text" maxlength="32" placeholder="最长32个字符" v-model="AddModalData.pointName" class="modal-text f-l">
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l">
                平台名称：
              </div>
              <input type="text" maxlength="32" placeholder="最长32个字符" v-model="AddModalData.platformName" class="modal-text f-l">
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l">
                扩展属性表：
              </div>
              <input type="text" readonly="readonly" v-model="AddModalData.owner" class="modal-text f-l">
            </div>

            <div class="modal-row f-l" >
              <div class="modal-form-key f-l">
                资源类型编码：
              </div>
              <select class="modal-text" @change="attrTable" :value="AddModalData.code">
                <option value="360°全景摄像机">360°全景摄像机</option>
                <option value="人像识别摄像机">人像识别摄像机</option>
                <option value="热成像摄像机">热成像摄像机</option>
                <option value="AR高点摄像机">AR高点摄像机</option>
                <option value="枪式摄像机">枪式摄像机</option>
                <option value="球式摄像机">球式摄像机</option>
                <option value="道路卡口摄像机">道路卡口摄像机</option>
                <option value="电子警察摄像机">电子警察摄像机</option>
                <option value="停车场卡口摄像机">停车场卡口摄像机</option>
                <option value="交通信号灯">交通信号灯</option>
                <option value="烽火摄像机">烽火摄像机</option>
              </select>
            </div>

         <!--   <div class="modal-row f-l" >
              <div class="modal-form-key f-l">
                大图：
              </div>
              <input type="text" v-model="AddModalData.bimage" class="modal-text f-l">
            </div>

            <div class="modal-row f-l">
              <div class="modal-form-key f-l">
                小图：
              </div>
              <input type="text" v-model="AddModalData.simage" class="modal-text f-l">
            </div>-->

            <div class="modal-row f-l" >
              <div class="modal-form-key f-l">
                备注：
              </div>
              <textarea maxlength="500" placeholder="最长500个字符" v-model="AddModalData.remark" class="modal-text f-l"></textarea>
            </div>

          </div>
          <div class="map-data-show"
               :style="{right: openMapDataContentIsShow ? '600px':'-40px'}"
               @click="openMapDataContent"
               title="录入地图信息"
          >
            <span class="glyphicon"
                  :class="{'glyphicon-chevron-left':!openMapDataContentIsShow,'glyphicon-chevron-right':openMapDataContentIsShow}">
            </span>
            <span class="glyphicon"
                  :class="{'glyphicon-chevron-left':!openMapDataContentIsShow,'glyphicon-chevron-right':openMapDataContentIsShow}">
            </span>
          </div>
        </div>
        <div class="btns text-r">
          <button type="button" class="btn btn-default"  @click="close">取消</button>
          <button type="button" class="btn btn-info" @click="subBtn">确定</button>
        </div>
        <!--{{userDetailsModal.obj}}-->
      </div>
    </div>
  </transition>
</template>

<script>
    import pointMap from "../../map/pointMap/pointMap"
    export default {
        name: "AddCameraModal",
        props:["addModalObj"],
        data(){
          return{
            AddModalData:{
              accout:'', //账号
              address:'', //地址
              bimage:'', //大图
              category:'1', //摄像头类型
              stationid:'', //部门id
              ipAddress:'',//ip
              isonline:'1', //是否在线
              maintenanceUnit:'湖北金鹏', //维护单位
              maintenanceUnitTel:'18745612347', //维护单位电话
              name:'', //名称
              num:'', //设备号
              simage:'', //小图
              latitude:'', //纬度
              longitude:'', //经度
              pointName:'', //点位名称
              owner:'T_RES_CAMERA', //扩展属性表
              code:'360°全景摄像机', //资源类型编码
              password:'', //密码
              poleNum:'', //杆号
              remark:'', //备注
              platformName:'', //平台名称
              installTime:'' //安装时间
            },
            point:[114.21868761726246, 30.584733852070247],
            actionType:null,
            carTypeList:[],
            stationName:'',
            setting : {
              data: {
                simpleData: {
                  enable: true
                },
              }
            },
            sectionTreeIShow:false,
            isPolygonButton: false, // 不现实画面按钮
            openMapDataContentIsShow: false
          }
        },
        components:{
          pointMap,
        },
        methods:{
          //提交
          subBtn(){

            //console.log(this.$refs.installTime.value);
            this.AddModalData.installTime = this.$refs.installTime.value;
            this.AddModalData.installTime ?  this.AddModalData.installTime = this.AddModalData.installTime+"T02:09:17.245+05:30":this.AddModalData.installTime = "";
            //console.log(this.AddModalData);
            //return false;
            if( this.verifyForm.isNull(this.AddModalData.accout) ){
              this.s_alert("账号不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.password) ){
              this.s_alert("密码不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.address) ){
              this.s_alert("地址不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.name) ){
              this.s_alert("名称不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.num) ){
              this.s_alert("设备号不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.installTime) ){
              this.s_alert("安装时间不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.stationid) ){
              this.s_alert("所属单位不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.ipAddress) || this.verifyForm.isIP(this.AddModalData.ipAddress) ){
              this.s_alert("IP为空或格式不正确！");
              return false;
            }
            else if( this.verifyForm.isNull(this.AddModalData.address) ){
              this.s_alert("地址不能为空！");
              return false;
            }
            else if( this.verifyForm.isIphoneOrTell(this.AddModalData.maintenanceUnitTel) ){
              this.s_alert("维护单位电话格式不正确！");
              return false;
            }
            else if( this.verifyForm.ifLongitude(this.AddModalData.longitude) ){
              this.s_alert("经度格式或区间不正确！正负180以内！");
              return false;
            }
            else if( this.verifyForm.ifLatitude(this.AddModalData.latitude) ){
              this.s_alert("纬度格式不正确！正负90以内！");
              return false;
            }

            this.$axios.post(this.DotCtrl+"/camera/addCameraInfo",this.AddModalData)
              .then((data)=>{
                //console.log(data);
                this.s_alert("新增成功！");
                this.s_logwrite("点位信息管理-摄像头管理","新增摄像头");
                this.close();
              })
              .catch((err)=>{
                this.s_alert(err.response.data.errorMsg);
                //this.s_alert("新增失败！");
                console.log(err.response.data);
              })
          },
          //是否在线
          selectIsOnline(ele){
            ////console.log(ele.target.value);
            this.AddModalData.isonline = ele.target.value;
          },
          selectCameraType(ele){
            ////console.log(ele.target.value);
            this.AddModalData.category = ele.target.value;
          },
          attrTable(ele){
            ////console.log(ele.target.value);
            this.AddModalData.code = ele.target.value
          },
          //展开部门树
          getStationTree(){
            this.sectionTreeIShow = !this.sectionTreeIShow;
            if( this.sectionTreeIShow ){
              this.getStationTreeAjax()
            }
          },
          //加载部门树
          getStationTreeAjax(){
            this.$axios.get(this.HOST+'/station/getOrgaInfo')
              .then((data)=>{
                $.fn.zTree.init($("#sectionTree"), this.setting, data.data.data);
                //console.log(data);
              })
              .catch((err)=>{
                //console.log(err);
              })
          },
          //关闭弹窗
          close(){
            this.$emit("addModalClose");
            this.clearData(); //关闭弹窗清除数据
          },
          //获取地图经纬度
          pointCoordinate(data){
            //console.log(data);
            this.AddModalData.longitude = data[0];
            this.AddModalData.latitude= data[1];
          },
          //清除数据
          clearData(){
            this.AddModalData={
              accout:'', //账号
              address:'', //地址
              bimage:'', //大图
              category:'1', //摄像头类型
              stationid:'', //部门id
              ipAddress:'',//ip
              isonline:'1', //是否在线
              maintenanceUnit:'湖北金鹏', //维护单位
              maintenanceUnitTel:'18745612347', //维护单位电话
              name:'', //名称
              num:'', //设备号
              simage:'', //小图
              latitude:'', //经度
              longitude:'', //纬度
              pointName:'', //点位名称
              owner:'T_RES_CAMERA', //扩展属性表
              code:'360°全景摄像机', //资源类型编码
              password:'', //密码
              poleNum:'', //杆号
              remark:'', //备注
              platformName:'', //平台名称
              installTime:'', //安装时间
              deviceType:'' //资源类型
            };
            this.stationName="";
            this.$refs.installTime.value = "";
            this.openMapDataContentIsShow = false;
          },
          //展开地图数据录入界面
          openMapDataContent(){
            this.openMapDataContentIsShow = !this.openMapDataContentIsShow;
          }
        },
        mounted(){
          let _this = this;
          this.setting.callback = {
            onClick:function(event,treeId,treeNode){
              //新增警员部门树选择
              //console.log(treeNode);
              _this.AddModalData.stationid = treeNode.id;
              _this.stationName = treeNode.name;
              _this.sectionTreeIShow = !_this.sectionTreeIShow;
            }
          };
          $(function () {
            //console.log($("#addDatetimepicker"));
            $('#date1').datetimepicker({
              language: "zh-CN",
              format: "yyyy-mm-dd",
              minView: "month",
              autoclose: true
            }).on("changeDate",function(ev){
              ////console.log(ev.date.valueOf());
              let selectDate = ev.date.valueOf();
              let theDate = new Date().getTime(); //当前时间
              if( selectDate >= theDate ){
                _this.s_alert("选择时间不能是未来时间！");
                $("#addDatetimepicker").val("");
                $("#addDatetimepicker").prev().val("");
              }
            });
          });
        }
    }
</script>

<style scoped>
  .sectionTree{
    position: absolute;
    top: 30px;
    right: 0;
    width: 60%;
    z-index: 10;
    background-color: #fff;
    border:1px solid rgba(51,51,51,0.2);
    box-sizing: border-box;
    padding: 5px;
    max-height: 200px;
    overflow-y: auto;
  }
  .fadeInDown,.fadeOutUp{
    animation-duration: .500s;
  }
  .form-control {
    height: 100%;
    border: 1px solid #ccc;
  }
</style>
